//
//  RYDingdanCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/25.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit
import YYText

class RYDingdanCell: SYBaseCell {
    
    var model: RYDingdanListModel!

    fileprivate var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 5
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x0F0F0F)
        v.font = 14.autoFontSize()
        return v
    }()
    
    let stateLb: UILabel = {
        let v:UILabel = UILabel()
        v.font = 13.autoFontSize()
        
        return v
    }()
    
    let dingdanhaoLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 13.autoFontSize()
        return v
    }()
    
    let timeLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 13.autoFontSize()
        return v
        
    }()
    
    let totalLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 13.autoFontSize()
        
        return v
    }()
    
    let hejiLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 13.autoFontSize()
        
        return v
    }()
    
    let totalRight: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 13.autoFontSize()
        
        return v
    }()
    
    let hejiRight: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x999999)
        v.font = 13.autoFontSize()
        
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.image = UIImage(named: "dingdan_list")
        return v
    }()
    
    let wuping: RYDingdanWupingListView = {
        let v: RYDingdanWupingListView = RYDingdanWupingListView()
        return v
    }()
    
    let chakan: UIButton = {
        let v: UIButton  = UIButton()
        v.setTitle("查看认养", for: .normal)
        v.setTitleColor(UIColor(hex: 0x367FF6), for: .normal)
        v.titleLabel?.font = 14.autoFontSize()
        v.layer.cornerRadius = 14.autoWidth()
        v.backgroundColor = UIColor(hex: 0xE6EEFE)
        return v
    }()
    
    let cancel: UIButton = {
        let v: UIButton  = UIButton()
        v.setTitle("取消支付", for: .normal)
        v.setTitleColor(UIColor(hex: 0x367FF6), for: .normal)
        v.titleLabel?.font = 14.autoFontSize()
        v.layer.cornerRadius = 14.autoWidth()
        v.backgroundColor = UIColor(hex: 0xE6EEFE)
        return v
    }()
    
    let zhifu: UIButton = {
        let v: UIButton  = UIButton()
//        v.setTitle("立即支付", for: .normal)
//        v.setTitleColor(UIColor(hex: 0x367FF6), for: .normal)
//        v.titleLabel?.font = 14.autoFontSize()
//        v.layer.cornerRadius = 14.autoWidth()
//        v.backgroundColor = UIColor(hex: 0xE6EEFE)
        v.setImage(UIImage(named: "lijizhifu"), for: .normal)
        return v
    }()
    
    let price: YYLabel = {
        let v:YYLabel = YYLabel()
        v.textColor = UIColor(hex: 0x1D1D1D)
        v.font = 16.autoFontSize()
        return v
    }()
    
    let priceRight: YYLabel = {
        let v:YYLabel = YYLabel()
        v.textColor = UIColor(hex: 0x1D1D1D)
        v.font = 16.autoFontSize()
        return v
    }()
    
    public var firLineView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0xE6E6E6)
        return v
    }()
    
    public var secLineView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0xE6E6E6)
        return v
    }()
    

    func configure(_ model: RYDingdanListModel) {
        
        self.model = model
        wuping.configure(model)
        let priceStr: String = "\(model.adoptFarmProductVO?.adoptPrice ?? 0)"
        price.attributedText = self.setPriceLb(priceStr)
        nameLb.text = model.farmName
        
        stateLb.text = model.getRenyangStatus()
        self.getRenyangStatusColor(model.adoptStatus)
        
        dingdanhaoLb.text = "订单号：\(model.orderNumber ?? "")"
        timeLb.text = model.orderTime ?? ""
        totalLb.text = "共\(model.orderQuantity)件商品"
        hejiLb.text = "合计"
        
        
    }
    
    func getRenyangStatusColor(_ status: Int) {
        
        chakan.isHidden = false
        cancel.isHidden = true
        zhifu.isHidden = true
        totalRight.isHidden = true
        hejiRight.isHidden = true
        priceRight.isHidden = true
        
       
        switch status {
   
        case 1:
            stateLb.textColor = UIColor(hex: 0xf55035)
            
            chakan.isHidden = true
            cancel.isHidden = false
            zhifu.isHidden = false
            totalRight.isHidden = false
            hejiRight.isHidden = false
            priceRight.isHidden = false
            
        case 2:
            stateLb.textColor = UIColor(hex: 0x00C793)
            
        case 3:
            stateLb.textColor = UIColor(hex: 0x367ff6)
            
        case 4:
            stateLb.textColor = UIColor(hex: 0x909090)
            
        default:
            break
        }
    }
    
    override func initViews() {
        chakan.addAction {[weak self] in
            if let `self` = self {
                let vc = RYVideoViewController(id: self.model.farmProductId)
                self.currentVC.navigationController?.pushViewController(vc, animated: true)
            }
        }
        self.backgroundColor = Constant.bgViewColor
            contentView.addSubview(bgView)
        bgView.addSubview(pic)
        bgView.addSubview(nameLb)
        bgView.addSubview(stateLb)
        bgView.addSubview(dingdanhaoLb)
        bgView.addSubview(timeLb)
        
        bgView.addSubview(totalLb)
        bgView.addSubview(hejiLb)
        bgView.addSubview(wuping)
        bgView.addSubview(chakan)
        bgView.addSubview(nameLb)
        bgView.addSubview(price)
        
        bgView.addSubview(lineView)
        bgView.addSubview(firLineView)
        bgView.addSubview(secLineView)
        
        bgView.addSubview(cancel)
        bgView.addSubview(zhifu)
        
        bgView.addSubview(totalRight)
        bgView.addSubview(priceRight)
        bgView.addSubview(hejiRight)
        
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(autoWidth(10.0))
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(286.0.autoWidth())
            make.bottom.equalToSuperview()
        }
        pic.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(autoWidth(15.0))
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.height.width.equalTo(17.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(pic)
            make.left.equalToSuperview().offset(autoWidth(39.0))
            make.height.equalTo(15.0.autoWidth())
        }
        stateLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(pic)
            make.right.equalToSuperview().offset(autoWidth(-16.0))
            make.height.equalTo(15.0.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(41.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(0.5.autoWidth())
        }
        wuping.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(56.0.autoWidth())
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(100.5.autoWidth())
        }
        firLineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(171.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(0.5.autoWidth())
        }
        dingdanhaoLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(183.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.height.equalTo(15.5.autoWidth())
            
        }
        timeLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(183.0.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(15.5.autoWidth())
            
        }
        secLineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(208.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(0.5.autoWidth())
        }
        totalLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(223.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.height.equalTo(15.5.autoWidth())
        }
        hejiLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(248.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.height.equalTo(15.5.autoWidth())
        }
        price.snp.makeConstraints { (make) in
            make.bottom.equalTo(hejiLb)
            make.left.equalToSuperview().offset(autoWidth(50.0))
            make.height.equalTo(20.5.autoWidth())
        }
        chakan.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(233.0.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(28.0.autoWidth())
            make.width.equalTo(85.0.autoWidth())
        }
        cancel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(233.0.autoWidth())
            make.right.equalTo(zhifu.snp.left).offset(autoWidth(-10.0))
            make.height.equalTo(28.0.autoWidth())
            make.width.equalTo(85.0.autoWidth())
        }
        
        zhifu.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(233.0.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(28.0.autoWidth())
            make.width.equalTo(85.0.autoWidth())
        }
        
        totalRight.snp.remakeConstraints { (make) in
            make.top.equalToSuperview().offset(223.0.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(15.5.autoWidth())
        }
        hejiRight.snp.remakeConstraints { (make) in
            make.top.equalToSuperview().offset(248.0.autoWidth())
            make.right.equalTo(price.snp.left).offset(autoWidth(-5.0))
            make.height.equalTo(15.5.autoWidth())
        }
        priceRight.snp.remakeConstraints { (make) in
            make.bottom.equalTo(hejiLb)
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(20.5.autoWidth())
        }
    }
}


